#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QMessageBox>


MainWindow::MainWindow(QWidget *parent)
  : QMainWindow(parent)
  , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->stackedWidget->insertWidget(0, &adsPage);
    ui->stackedWidget->insertWidget(1, &proflPage);
    ui->stackedWidget->insertWidget(2, &saleStatusPage);
    ui->stackedWidget->insertWidget(3, &employeePage);
    ui->stackedWidget->insertWidget(4, &editAdsPage);
    ui->stackedWidget->insertWidget(5, &editprofile);
    ui->stackedWidget->setCurrentIndex(1);

    connect(&employeePage, &EmployeePage::editpageshow, this, &MainWindow::showEditProfile);
    connect(&adsPage, &Adspage::editadspageshow, this,  &MainWindow::showEditAds);

    Singleton* s1 = Singleton::getInstance();
    if(s1->role == "Admin")
    {
        ui->line_2->show();
        ui->employeeButtonShowPage->show();
    }
    else
    {
        ui->line_2->hide();
        ui->employeeButtonShowPage->hide();
    }
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_adsButtonShowPage_clicked()
{
    ui->stackedWidget->setCurrentIndex(0);
}

void MainWindow::on_profileButtonShowPage_clicked()
{
    ui->stackedWidget->setCurrentIndex(1);
}


void MainWindow::on_employeeButtonShowPage_clicked()
{
    ui->stackedWidget->setCurrentIndex(3);
}


void MainWindow::on_exitButton_clicked()
{
    this->close();

}


void MainWindow::on_aboutButton_clicked()
{
    QMessageBox::aboutQt(0, "О программе");
}


void MainWindow::on_pushButton_clicked()
{
    ui->stackedWidget->setCurrentIndex(2);
}

void MainWindow::showEditProfile()
{
    ui->stackedWidget->setCurrentIndex(5);
}

void MainWindow::showEditAds()
{
    ui->stackedWidget->setCurrentIndex(4);
}

